package com.wuyou.mid;

/**
 * 1653. 使字符串平衡的最少删除次数
 */
public class MinimumDeletions {

    // "aababbab"
    // "bbaaaaabb"
    public static int sol_1(String s) {
        char[] c = s.toCharArray();
        int countB = 0, dp = 0;

        for (int i = 0; i < c.length; i++) {
            if (c[i] == 'a') {
                dp = Math.min(dp + 1, countB);
            } else {
                countB++;
            }
        }
        return dp;
    }
}
